home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OCFSRC.PAK / OCDATA.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  237 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectComponents
  3. // Copyright (c) 1994, 1997 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   2.8  $
  6. //
  7. // Implementation of TOcDataProvider Class
  8. //----------------------------------------------------------------------------
  9. #include <ocf/pch.h>
  10. #if !defined(OCF_OCAPP_H)
  11. # include <ocf/ocapp.h>
  12. #endif
  13. #if !defined(OCF_OCDATA_H)
  14. # include <ocf/ocdata.h>
  15. #endif
  16.  
  17. //
  18. //
  19. //
  20. TOcDataProvider::TOcDataProvider(TOcView& ocView, TRegList* regList, IUnknown* outer,
  21.                                  void* userData, TDeleteUserData callBack)
  22. :
  23.   OcView(ocView), BSite(0), BSiteI(0), BLSiteI(0),
  24.   UserData(userData), CBDelete(callBack),
  25.   Origin(0,0),
  26.   Extent(0,0)
  27. {
  28.   SetOuter(outer);
  29.   AddRef();    // TUnknown defaults to 0, we need 1
  30.  
  31.   // Create a site for this data provider
  32.   //
  33.   if (SUCCEEDED(OcView.OcApp.BOleComponentCreate(&BSite, (IUnknown*)(IBDataProvider*)this,
  34.       cidBOleSite))) {
  35.  
  36.     if (SUCCEEDED(BSite->QueryInterface(IID_IBSite, &(LPVOID)BSiteI)))
  37.       Release();
  38.  
  39.     // Connect the part and the site
  40.     //
  41.     if (BSiteI) {
  42.       const char* progid = regList->Lookup(OcView.OcApp.IsOptionSet(amDebug) ?
  43.                                            "debugprogid" : "progid");
  44.       BSiteI->Init(this, 0, OleStr(progid), true);
  45.     }
  46.  
  47.     if (SUCCEEDED(BSite->QueryInterface(IID_IBLinkable,&(LPVOID)BLSiteI)))
  48.       BLSiteI->Release();   // avoid deadlock
  49.  
  50.     // Remember the dataprovider in OcView
  51.     //
  52.     OcView.SetOcData(this);
  53.  
  54.     // Set up monikers for selection
  55.     //
  56.     Rename();
  57.   }
  58. }
  59.  
  60. //
  61. //
  62. //
  63. TOcDataProvider::~TOcDataProvider()
  64. {
  65.   // If the TOcDataProvider object is released by the clipboard
  66.   //
  67.   if (OcView.GetOcData() == this)
  68.     OcView.SetOcData(0);
  69.  
  70.   // User data clean up
  71.   //
  72.   if (CBDelete)
  73.     CBDelete(UserData);
  74.  
  75.   if(BSite)
  76.     BSite->Release();
  77. }
  78.  
  79. //
  80. //
  81. //
  82. HRESULT
  83. TOcDataProvider::QueryObject(const IID far& iid, void far* far* iface)
  84. {
  85.   PRECONDITION(iface);
  86.   HRESULT hr;
  87.  
  88.   // interfaces
  89.   //
  90.      SUCCEEDED(hr = IBDataProvider_QueryInterface(this, iid, iface))
  91.  
  92.   // helpers
  93.   //
  94.   || (BSite && SUCCEEDED(hr = BSite->QueryInterface(iid, iface)))
  95.   ;
  96.  
  97.   return hr;
  98. }
  99.  
  100. //
  101. // Disconnect from the site
  102. //
  103. void
  104. TOcDataProvider::Disconnect()
  105. {
  106.   if (BSiteI)
  107.     BSiteI->Disconnect();
  108. }
  109.  
  110. //
  111. // Update item moniker with new name
  112. //
  113. void
  114. TOcDataProvider::Rename()
  115. {
  116.   PRECONDITION(BLSiteI);
  117.  
  118.   OcView.Rename();
  119.  
  120.   // Update the item's moniker
  121.   //
  122.   TOcItemName item(true);
  123.   if (OcView.ServerHost->EvOcViewGetItemName(item))
  124.     BLSiteI->OnRename(OcView.BLDocumentI, OleStr(item.Name));
  125. }
  126.  
  127. //
  128. //
  129. //
  130. UINT _IFUNC
  131. TOcDataProvider::CountFormats()
  132. {
  133.   return OcView.CountFormats();
  134. }
  135.  
  136. //
  137. //
  138. //
  139. HRESULT _IFUNC
  140. TOcDataProvider::GetFormat(uint index, TOcFormatInfo far* fmt)
  141. {
  142.   PRECONDITION(fmt);
  143.  
  144.   return OcView.GetFormat(index, fmt);
  145. }
  146.  
  147. //
  148. // Request native data for pasting into client application.
  149. // This is only called at paste time (not at copy time).
  150. //
  151. HANDLE _IFUNC
  152. TOcDataProvider::GetFormatData(TOcFormatInfo far* fmt)
  153. {
  154.   PRECONDITION(fmt);
  155.  
  156.   TOcFormat* format = OcView.FormatList.Find(fmt->Id);
  157.   if (format && *format->GetRegName()) {
  158.     TOcFormatData formatData(*format, UserData);
  159.     if (OcView.ServerHost->EvOcViewClipData(formatData))
  160.       return formatData.Handle;
  161.   }
  162.  
  163.   return 0;
  164. }
  165.  
  166. //
  167. // Render the data in the DC provided. May be a MetaFile
  168. // Packup all the args & forward message to real view to paint
  169. //
  170. HRESULT _IFUNC
  171. TOcDataProvider::Draw(HDC dc, const RECTL far* pos, const RECTL far* clip,
  172.                  TOcAspect aspect, TOcDraw bd)
  173. {
  174.   PRECONDITION(dc);
  175.   bool metafile = ::GetDeviceCaps(dc, TECHNOLOGY) == DT_METAFILE;
  176.  
  177.   // Rely on the bolero shading
  178.   //
  179.   if (bd == drShadingOnly)
  180.     return HR_NOERROR;
  181.  
  182.   TRect p((int)pos->left, (int)pos->top, (int)pos->right, (int)pos->bottom);
  183.   TRect c((int)clip->left, (int)clip->top, (int)clip->right, (int)clip->bottom);
  184.  
  185.   if (metafile) {
  186.     p.SetNull();
  187.     ::SetMapMode(dc, MM_ANISOTROPIC);
  188.  
  189.     ::SetWindowExtEx(dc, Extent.cx, Extent.cy, 0);
  190.     ::SetWindowOrgEx(dc, 0, 0, 0);
  191.   }
  192.  
  193.   p.Normalize();
  194.   c.Normalize();
  195.   TOcViewPaint vp = { dc, &p, &c, (TOcAspect)aspect, true, 0, UserData };
  196.  
  197.   return HRFailIfZero(OcView.ServerHost->EvOcViewPaint(vp));
  198. }
  199.  
  200. //
  201. // Return the 'size' of the document that this view is on
  202. //
  203. HRESULT _IFUNC
  204. TOcDataProvider::GetPartSize(TSize far* size)
  205. {
  206.   TOcPartSize ps(true, 0, UserData);
  207.  
  208.   // Ask the app for initial server extent
  209.   //
  210.   if (!OcView.ServerHost->EvOcViewPartSize(ps)) {
  211.     // An empty rect as default means that the container
  212.     // decides the size for this server
  213.     //
  214.     ps.PartRect.SetNull();
  215.   }
  216.  
  217.   Extent = ps.PartRect.Size();
  218.   Origin = ps.PartRect.TopLeft();
  219.  
  220.   *size = Extent;
  221.   return HR_NOERROR;
  222. }
  223.  
  224. //
  225. // Save the selection that we are a view on
  226. //
  227. HRESULT _IFUNC
  228. TOcDataProvider::Save(IStorage* storage, BOOL sameAsLoad, BOOL remember)
  229. {
  230.   PRECONDITION(storage);
  231.  
  232.   TOcSaveLoad ocSave(storage, ToBool(sameAsLoad), ToBool(remember), true,
  233.                      UserData);
  234.  
  235.   return HRFailIfZero(OcView.ServerHost->EvOcViewSavePart(ocSave));
  236. }
  237.